#include "MathLib.h"
#include <math.h>

using namespace math;

Vertex Matrix::TransformVert(Vertex &p_Vertex) {
	
	return Vertex(cell[0] * p_Vertex[0] + cell[4] * p_Vertex[1] + cell[8] * p_Vertex[2] + cell[12]
				,cell[1] * p_Vertex[0] + cell[5] * p_Vertex[1] + cell[9] * p_Vertex[2] + cell[13]
				,cell[2] * p_Vertex[0] + cell[6] * p_Vertex[1] + cell[10] * p_Vertex[2] + cell[14]);   
}   

flt math::Vector::Length()
{
	float length = data[0]*data[0] + data[1]*data[1] + data[2]*data[2];
	return pow(length, 0.5f);
}

void math::Vector::Normalize() {
	float length = data[0]*data[0] + data[1]*data[1] + data[2]*data[2];
	length = pow(length,0.5f);
	data[0] /= length;
	data[1] /= length;
	data[2] /= length;
}	


Vector & math::Vector::operator*=(const flt p_dist)
{
	this->data[0] *= p_dist;
	this->data[1] *= p_dist;
	this->data[2] *= p_dist;
    return *this; 	
}

const Vector math::Vector::operator*(const flt p_dist) const
{
	math::Vector result = *this;    
    result*= p_dist;            
    return result;      
}

Vertex& math::Vertex::operator+=(const Vector &p_Vector)
{
	this->data[0] += p_Vector.data[0];
	this->data[1] += p_Vector.data[1];
	this->data[2] += p_Vector.data[2];
	return *this;
}

const Vertex math::Vertex::operator+(const Vector &p_Vector) const 
{
    Vertex result = *this;    
    result += p_Vector;            
    return result;             
} 

Vector Vector::Cross(Vector &p_Vector1, Vector &p_Vector2)
{
	return Vector(p_Vector1[1]*p_Vector2[2] - p_Vector1[2] * p_Vector2[1],
				p_Vector1[2]*p_Vector2[0] - p_Vector1[0] * p_Vector2[2], 
				p_Vector1[0]*p_Vector2[1] - p_Vector1[1] * p_Vector2[0]); 
}
